// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var html_financingDetail_financeContract = require("../financing/financingDetail_financeContract.html");
	var html_financingDetail_supervisionContract = require("../financing/financingDetail_supervisionContract.html");
	var html_financingDetail_recieveNotice = require("../financing/financingDetail_recieveNotice.html");
	var html_financingDetail_recieveNotice_warehouse = require("./html_financingDetail_recieveNotice_warehouse.html");
	var html_financingDetail_supervisionInform = require("../financing/financingDetail_supervisionInform.html");
	var html_documentSign = require("./html_documentSign.html");
	var html_signFileSealList = require("./html_signFileSealList.html");
	var html_savePos = require("./html_savePosInfo.html");
	var html_signCallback = require("./html_signCallback.html");
	var html_contractConfirm = require("./html_contractConfirm.html");
	var html_signReplace = require("./html_signReplace.html");
	var css_financeManage = require("../financing/financingManage.css");
	var css_financeDetailInfo = require("../financing/financingDetailInfo.css");
	var js_platform_main = require("./platform_main.js");
	var css_main_finance = require("./main_finance.css");
	var dialog = require("dialog");
	var validate = require("validate");
	var constant = require("constant")
	var databind = require("databind");
	var constractState;
	var financeConstractState;
	var ei;
	var contractType;
	var record;
	var rd;
	var ii3;
	var ii2;
	var ii;
	var ii4;
	var tools = require("tools");
	var html_constractCallBack = require("./html_constractCallBack.html");
	// var css_dialog = require("css_dialog");
	var pageIndex = 1, pageSize = 10, totalPageCount = 1, totalRecordCount = 0; // 分页初始化
	var imgSrc;
	var left;
	var financeState;
	var financeId;
	var contractTypeName;
	var financeNumber;
	var dataFinancingDetail;
	var receive;
	var deliver;
	var pt;
	var init = function(page) {
		if (page.params == null) {
			left = 1;
			financeState = 1;
		} else {
			left = page.params.left;
			financeState = page.params.financeState;
			contractType = page.params.contractType;
		}
		
		
		if (contractType != null && contractType == 1) {
			contractTypeName = "融资协议";
		} else if (contractType != null && contractType == 2) {
			contractTypeName = "融资合同";
		} else if (contractType != null && contractType == 4) {
			contractTypeName = "增补合同";
		}
		
		
		personalWorkbench();
		$(".left").removeClass("none");
		if ($(".topMenu li.topMenu_selected").attr("id") == "home") {
			leftMenu.init(6);
			$("#leftMenu7").find(".leftMenu-item").removeClass("leftMenu-active");
			$("#leftMenu7").find(".leftMenu-item").eq(left).addClass("leftMenu-active");
		}
		$(".table-section").removeClass("none");
		$(".footer").removeClass("none");
		$("#main").css("background", "#ffffff");
		$("#leftMenu7 .leftMenu li:first-child").addClass("leftMenu-open");
		inquireFinanceList();
		initEvent();
		router.init();
	};
	var initEvent = function() {
		// 若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == ""
				|| base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}

		// 点击首页
		$(".platform_main").unbind("click").click(function() {
			top.location.href = "../main/platform_main.html";
		});

		$("#main_finance .seatchButon").unbind("click").click(function() {
			pageIndex = 1;
			if ($("#main_finance .searchStatus").val() == 1) {
				inquireFinanceList1();			
			} else {
				inquireFinanceList();
			}
		});

	};
	
	// 点击融资合同
	var submit_financeContract_event = function() {
		// submit-supervisionContract
		$("#popdialog").html(html_financingDetail_financeContract);
		inquireSystemParamByName($("#showContractTemplate1"), "融资合同范本");
		var financeContract_dialog = $("#financeContract_dialog");
		$("#financeContract_dialog input[name=contractType]").val(contractType);
		$("#financeContract_dialog .dialogTitle").html(contractTypeName + "信息");
		
		dialog.showDialog(financeContract_dialog, function() {});
		inquireFinanceContract();
		
		//附件
		$("#financeContract_dialog").on("change", "#electronicSealFile", function(){
			var arry1="";
			var arry2="";
			tools.uploadFile("electronicSealFile", function(data){
				if ($.trim($("#materials").val()) == "") {
					arry1 = data.data[0].fileUuid;
				} else {
					arry1=$("#materials").val() + "," + data.data[0].fileUuid;
				}
				$("#materials").val($.trim(arry1));
				if ($.trim($("#imageNames").val()) == "") {
					arry2 = data.data[0].fileName;
				} else {
					arry2=$("#imageNames").val() + "," + data.data[0].fileName;
				}
				$("#imageNames").val($.trim(arry2));

			});
		});
		
		// 上传附件
		$("#uploadFile1024").on('change', function() {
			uploadFile();
		});

		$(".uploadImgP").on("click", ".closeLayer", function() {
			$(this).parent().remove();
			saveMaterials();
		});
		
		if (financeState == 31) {
			$("input[name=isSign]").parent().hide();
		}
		
		$("#sure_yes").on("click", function() {
			if (financeState == 31) {
				var ii2 = layer.confirm('是否确认提交 提交后将不可修改！', {
				  btn: ['确定','取消'] //按钮
				}, function(){
				  createFinanceContract();
				}, function(){
				  
				});
			} else {
				if (constractState != "0" && constractState != "1" && constractState != "2") {
					dialog.hideDialog($("#financeContract_dialog"));
				} else {
					var financeContractIdVar = $("#financeContractId").val();
					if (financeContractIdVar.length == 0) {
						createFinanceContract();
					} else {
						updateFinanceContract();
					}
				}
			}
			
		});

		inquireCurrentOperationList();
	}
	// 点击监管合同
	var submit_supervisionContract_event = function() {
		// submit-supervisionContract
		$("#popdialog").html(html_financingDetail_supervisionContract);
		inquireSystemParamByName($("#showContractTemplate2"), "监管合同范本");
		var supervisionContract_dialog = $("#supervisionContract_dialog");
		dialog.showDialog(supervisionContract_dialog, function() {
		});
		loadLogisticsCompanyPageList("supervisionCompanyName", "supervisionTpl");
		// 上传附件
		$("#uploadFile1024").on('change', function() {
			uploadFile();
		});
		inquireFinanceSupervisionContract();
		$(".uploadImgP").on("click", ".closeLayer", function() {
			$(this).parent().remove();
			saveMaterials();
		});

		$("#sure_yes").on("click", function() {
			var supervisionContractId = $("#supervisionContractId").val();
			if (supervisionContractId.length == 0) {
				createSupervisionContract();
			} else {
				updateSupervisionContract();
			}
		});

	};
	
	//查询列表
	var inquireFinanceFilesNormList = function() {
		base.fnAjax({
			action: "inquireFinanceFilesNormList.json",
			async: false, //同步异步
			nocode: false, //是否要登陆，true为不用登陆
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#financeContract_dialog script").html();
					var html = juicer(tpl, data);
					$("#financeContract_dialog .normInfos").append(html);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};

	// 查询合同
	var inquireSystemParamByName = function(dom, str) {
		base.fnAjax({
			action : "inquireSystemParamByName.json",
			oData : {
				paramName : str
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					$(dom).find("a").attr(
							"href",
							"/finance/api/v1.0/downloadFile,file?fileUuid="
									+ data.datas[0].paramValue);
					$(dom).removeClass("none");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	}

	var initRecieveNoticeDialog = function() {
		$("#popdialog").html(html_financingDetail_recieveNotice);
		dialog.showDialog($("#recieveNotice_dialog"));
		$("#recieveNotice_dialog .data[name=financeNumber]").html(financeNumber);
		
		$(".dialogContent-recieveNotice").on("click", ".delete", function() {
			$(this).parent().parent(".trBulkstocks").remove();
		});

		$("#supervisionCompanyName").unbind("change").change(function() {
			$("#supervisionCompanyNameInput").val($(this).find("option:selected").text());
		});

		$("#sure_yes").on("click", function() {

			// 修改或者新加下发收货通知
			createOrUpdateRecieveNotice();

		});
		
		$("#recieveNotice_dialog a[name=financeNumber]").unbind("click").click(function(){
			dialog.hideDialog($("#recieveNotice_dialog"));
			router.route("financing/financingDetailInfo.html?financeId=" + financeId);
		});
	}

	// 修改或者新加下发收货通知
	var createOrUpdateRecieveNotice = function() {

		$.each($(".field-input-recieveNotice"), function(i, val) {
			if (val.value == undefined || val.value.length == 0) {
				if (val.name == "caseQuantity") {
					$(this).val(0);
				} else {
					$(this).val(" ");
				}

			}
		});
		databind.submitDom(".dialogContent-recieveNotice", function() {
			base.alert(1, "下发收货通知成功");
			dialog.hideDialog($("#recieveNotice_dialog"));
			router.route("main/main_finance.html?left=2&financeState=5", true);
		});
	}
	// 显示收货通知弹出框（新建）
	var showCreateRecieveNotice = function() {
		loadLogisticsCompanyPageList("supervisionCompanyName", "supervisionTpl");
		var html;
		var financingDetail_bulkstock = $("#financingDetail-bulkstock").html();
		if (financingDetail_bulkstock != undefined) {
			html = juicer(financingDetail_bulkstock,
					dataFinancingDetail.datas[0]);
		}
		$(".recieveNoticeTable").html(html);
		databind.fillForm(".dialogContent-recieveNotice",
				dataFinancingDetail.datas[0]);
		inquireSupervisionContractToSupervisionNotice();
		
		$(".recieveNoticeQuantity").unbind("change").change(function() {
			var re = /^[1-9]*[0-9]*$/;
			if(!re.test($(this).val())) {
				base.alert(2, "请输入正整数数字");
				return;
			}
			
			if (parseFloat($(this).val()) > parseFloat($(this).attr("id"))) {
				base.alert(2, "收货数量不能超过实际数量");
			}
		});
		
		setTimeout(function(){
			if (dataFinancingDetail.datas[0].productType == 4) {
				$("#supervisionCompanyName option[txt='"+ dataFinancingDetail.datas[0].deliver +"']").attr("selected", true);
				$("#supervisionCompanyNameInput").val($("#supervisionCompanyName").find("option:selected").text());
			}
		}, 1000);
	}

	// 点击收货通知
	var button_submit_recieveNotice_event = function() {
		base.fnAjax({
			action : "inquireFinanceSupervisionNotice.json",
			oData : {
				financeId : financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					initRecieveNoticeDialog();
					showCreateRecieveNotice();
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	// 平台-首页(待办事项)
	var personalWorkbench = function() {
		base.fnAjax({
			action : "personalWorkbench.json",
			async : false,
			oData : {}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					if (financeState == 1) {
						financeId = data.datas[0].audits;
					} else if (financeState == 3) {
						if (contractType == 1) {
							financeId = data.datas[0].contracts;
						} else if (contractType == 2) {
							financeId = data.datas[0].contracts1;
						} else if (contractType == 3) {
							financeId = data.datas[0].contracts2;
						}
					} else if (financeState == 5) {
						financeId = data.datas[0].recieves;
					} else if (financeState == 23) {
						financeId = data.datas[0].audits1;
					} else if (financeState = 31) {
						financeId = data.datas[0].supplementContracts;
					}
					
					if (financeId.length == 0) {
						financeId = [ 0 ];
					}
				} else {
					base.alert(2, "信息获取失败");
			 	}
			}
		});
	}
	// 查询融资信息列表
	var inquireFinanceList = function() {
		var productType = $("#main_finance select[name=productType]").val();
		var fb = $("#main_finance .financeNumber").val();
		base.fnAjax({
			action : "inquireFinanceList.json",
			async : false, // 同步异步
			nocode : false, // 是否要登陆，true为不用登陆
			oData : {
				pageIndex : pageIndex,
				pageSize : pageSize,
				financeId : financeId,
				financeNumber :fb,
				waybillNumber: $("#main_finance .waybillNumber").val(),
				enterpriseName: $("#main_finance .enterpriseName").val(),
				bulkstockName: $("#main_finance .bulkstockName").val(),
				productType : productType,
				caseNumber: $("#main_finance .caseNumber").val(),
				financeContractSerialNumber: $("#main_finance .financeContractSerialNumber").val()
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					juicer.register("formatCurrency", tools.formatCurrency);
					var tpl = $("#financeListTpl").html();
					var html = juicer(tpl, data);
					$("#financeListBody").html(html);

					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl(
						$("#pagenation"),
						totalRecordCount, data.pageIndex,
						data.pageSize, function(p) {
							pageIndex = p;
							inquireFinanceList();
					});
					changeStatusColor();
					// 点击融资编号
					$(".order_num").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						router.route("financing/financingDetailInfo.html?financeId=" + financeId, true);
					});

					if (financeState == 1 || financeState == 23) {
						$(".locationContract").html("融资审批");
						var detail = '<span class="approveDetail">进入审批</span>';
						
						$(".detail").append(detail);
						$(".contractState").addClass("none");
						tools.changeWarningColor($("#financeListBody"), "applicationCreateDatetime");
					} else if (financeState == 3) {
						$(".locationContract").html("合同上传");
						var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-submitContract ff2 permissionLink none" permissionId="financeContractSubmit_1">合同提交&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-confirmContract ff2 permissionLink none" permissionId="financeContractConfirm_1">合同确认&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-callBack ff2 permissionLink none" permissionId="financeCallBack_1">合同打回&nbsp;&nbsp;&nbsp;&nbsp;</div> </div>';
//						var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-submitContract ff2 permissionLink none" permissionId="financeContractSubmit_1">合同提交&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-confirmContract ff2 permissionLink none" permissionId="financeContractConfirm_1">合同确认&nbsp;&nbsp;&nbsp;&nbsp;</div> </div>';
//						<div class="submit-sample ff2">合同范本&nbsp;&nbsp;&nbsp;&nbsp;</div>
//							暂时不上传合同范本  <div class="submit-sample ff2">合同范本&nbsp;&nbsp;&nbsp;&nbsp;</div>
						$(".detail").append(detail);
						var s = '<div class="submit-signContract ff2 permissionLink none" permissionId="financeContractSign_1">我方签署&nbsp;&nbsp;&nbsp;&nbsp;</div>';
						var s1 = '<div class="submit-signEnterpriseContract ff2 permissionLink none" permissionId="financeEnterpriseContractSign_1">客户签署&nbsp;&nbsp;&nbsp;&nbsp;</div>';
						$.each($(".detail"), function(){
							var $this = $(this);
//							if ($this.parents("tr").attr("financestate1") == 22 && $this.parents("tr").attr("constractState") == 5) {
//								$this.parents("tr").find(".submit-submitContract").after(s);
//							}
							if ($this.parents("tr").attr("productType") == "5" || $this.parents("tr").attr("productType") == "6") {
								$this.parents("tr").find(".submit-callBack").remove();
							}
							if (contractType == "3") {
								$this.parents("tr").find(".submit-submitContract").after(s);
								$(".submit-financeContract").hide();
								$(".submit-submitContract").hide();
								$(".submit-confirmContract").hide();
								$(".submit-callBack").hide();
							}
							if ($this.parents("tr").attr("financestate1") == 24) {
								$this.parents("tr").find(".submit-submitContract").after(s1);
							}
							
							var financeConstractState = $(this).parents("tr").attr("financeConstractState");
							if (financeConstractState == "0") {
								//合同未上传 只显示融资合同菜单
								$this.parents("tr").find(".submit-submitContract").hide();
								$this.parents("tr").find(".submit-confirmContract").hide();
								$this.parents("tr").find(".submit-callBack ").hide();
							} else if (financeConstractState == "1") {
								//合同已上传 显示融资合同和合同提交
								$this.parents("tr").find(".submit-confirmContract").hide();
								$this.parents("tr").find(".submit-callBack ").hide();
							} else if (financeConstractState == "3") {
								//待客户签署 显示客户签署
								$this.parents("tr").find(".submit-financeContract").hide();
								$this.parents("tr").find(".submit-submitContract").hide();
								$this.parents("tr").find(".submit-confirmContract").hide();
								$this.parents("tr").find(".submit-callBack ").hide();
							} else if (financeConstractState == "4") {
								//客户已签署 显示合同确认
								$this.parents("tr").find(".submit-financeContract").hide();
								$this.parents("tr").find(".submit-submitContract").hide();
							} else if (financeConstractState == "7" || financeConstractState == "9") {
								//合同已打回 显示融资合同和合同提交
								$this.parents("tr").find(".submit-confirmContract").hide();
								$this.parents("tr").find(".submit-callBack ").hide();
							} else if (financeConstractState == "8") {
								//待确认 显示合同打回和合同确认
								$this.parents("tr").find(".submit-financeContract").hide();
								$this.parents("tr").find(".submit-submitContract").hide();
							}
							
						});
						inquireCurrentOperationList();
						tools.changeWarningColor($("#financeListBody"), "constractCreateDatetime");
					} else if (financeState == 5) {
						$(".locationContract").html("通知锁定");
						var detail = '通知锁定&nbsp;&nbsp;<div class="hideBtn"><div class="button-submit-recieveNotice ff2">通知锁定&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
						$(".detail").append(detail);
						tools.changeWarningColor($("#financeListBody"), "receiveCreateDatetime");
					} else if (financeState == 31) {
						$(".locationContract").html("合同上传");
						var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-submitContract ff2 permissionLink none" permissionId="financeContractSubmit_1">合同提交&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-confirmContract ff2 permissionLink none" permissionId="financeContractConfirm_1">合同确认&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-callBack ff2 permissionLink none" permissionId="financeCallBack_1">合同打回&nbsp;&nbsp;&nbsp;&nbsp;</div> </div>';
						$(".detail").append(detail);
						var s = '<div class="submit-signContract ff2 permissionLink none" permissionId="financeContractSign_1">我方签署&nbsp;&nbsp;&nbsp;&nbsp;</div>';
						var s1 = '<div class="submit-signEnterpriseContract ff2 permissionLink none" permissionId="financeEnterpriseContractSign_1">客户签署&nbsp;&nbsp;&nbsp;&nbsp;</div>';
						$.each($(".detail"), function(){
							var $this = $(this);
							if ($this.parents("tr").attr("productType") == "5" || $this.parents("tr").attr("productType") == "6") {
								$this.parents("tr").find(".submit-callBack").remove();
							}
							if (contractType == "3") {
								$this.parents("tr").find(".submit-submitContract").after(s);
								$(".submit-financeContract").hide();
								$(".submit-submitContract").hide();
								$(".submit-confirmContract").hide();
								$(".submit-callBack").hide();
							}
							if ($this.parents("tr").attr("financestate1") == 24) {
								$this.parents("tr").find(".submit-submitContract").after(s1);
							}
							
							if ($this.parents("tr").attr("financestate1") == 31) {
								//合同未上传 只显示融资合同菜单
								$this.parents("tr").find(".submit-submitContract").hide();
								$this.parents("tr").find(".submit-confirmContract").hide();
								$this.parents("tr").find(".submit-callBack ").hide();
							}
							
						});
						inquireCurrentOperationList();
					}
					
					if (financeState != 3) {
						$(".contractState").html("");
						$("#contrOne").addClass("none");
						$(".contractState").addClass("none");
					}
					
					//我方签署
					$(".submit-signContract").unbind("click").click(function() {
						var $this = $(this);
						
						ii = layer.open({
						  title: '合同信息',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_documentSign,
						  btn: ['确定']
						});
						
						inquireFinanceContract1($this.parents("tr").attr("financeId"), false);
						
					});
					
					//客户签署
					$(".submit-signEnterpriseContract").unbind("click").click(function() {
						var $this = $(this);
						
						ei = $(this).parents("tr").attr("enterpriseId");
						
						ii = layer.open({
						  title: '合同信息',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_documentSign,
						  btn: ['确定']
						});
						
						inquireFinanceContract1($this.parents("tr").attr("financeId"), true);
						
					});
					
					// 点击融资合同
					$(".submit-financeContract").unbind("click").click(function() {
						
						pt = $(this).parents("tr").attr("productType");
						constractState = $(this).parents("tr").attr("constractState");
						financeConstractState = $(this).parents("tr").attr("financeConstractState");
						var financeIds = [];
						var financeNumbers = [];
						var delivers = [];
						var receives = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						delivers.push($this.attr("receive"));
						receives.push($this.attr("deliver"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						deliver = delivers;
						receive = receives;
						submit_financeContract_event();
					});
					
					// 点击融资合同范本
					$(".submit-sample").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var delivers = [];
						var receives = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						delivers.push($this.attr("receive"));
						receives.push($this.attr("deliver"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						deliver = delivers;
						receive = receives;
						submit_financeContract_event();
						$("#financeContract_dialog .dialogTitle").html("上传合同范本");
						$("#uploadFile1024").attr("accept", ".pdf");
						$("#financeContract_dialog .remark").html("*附件上传支持pdf文件格式");
						$(".financeContract div div p").eq(2).append('<span class="field-lab2 financing_field-lab2" style="margin-left: 6px;">&nbsp;&nbsp;<span class="requiredInput">*</span> 是否平台盖章：<input  checked=checked name="isSign" type="checkbox" value="1"></span>');
						$("#financeContract_dialog input[name=financeContractNumber]").parent().after('<span class="field-lab2 financing_field-lab2"> <span class="requiredInput">*</span>签署关键字：<input class="field-input" name="signKey" placeholder="请输入关键字" value="更加发达的物质文明" readonly="readonly" isnull="1" codename="关键字" minlength="1" maxlength="255" type="text"><input class="field-input" name="url"  value="'+window.location.host+'" type="hidden"></span>');
						$("#financeContract_dialog input[name=contractSignDate]").parent().remove();
						
//						$("#financeContract_dialog").on("click", "a", function(){
//							var $this = $(this);
//							if ($("#financeContract_dialog .crossScreen").prop("checked") == true) {
//								$this.attr({"target": "", "href": "javascript:void(0);"});
//								if (rd == null) {
//									getRandomCode1(function(){
//										passInventoryId(rd, $this.attr("fhref"));
//										window.open("../crossingScreen/pc/index2.html?randomCode=" + rd);
//									});
//								} else {
//									passInventoryId(rd, $this.attr("fhref"));
//								}
//							} else {
//								$this.attr({"target": "_blank", "href": "/finance/api/v1.0/downloadFile.file?fileUuid=" + $this.attr("fhref")});
//							}
//						});
					});
					
					//合同打回
					$(".submit-callBack").unbind("click").click(function() {
						$("#popdialog").html(html_constractCallBack);
						$("#constractCallback_dialog input[name=financeId]").val($(this).parents("tr").attr("financeId"));
						$("#constractCallback_dialog input[name=financeContractId]").val($(this).parents("tr").attr("financeContractId"));
						$("#constractCallback_dialog input[name=contractType]").val(contractType);
						
						tools.inquireCommonSelectorListByName("费用名称", $("#constractCallback_dialog select[name=callBackReason]"))
						
						dialog.showDialog($("#constractCallback_dialog"));
						
						//取消按钮点击事件
						$("#constractCallback_dialog .sure_no").unbind("click").click(function(){
							dialog.hideDialog($("#constractCallback_dialog"));
						});
						
						//确定按钮点击事件
						$("#constractCallback_dialog .sure_yes").unbind("click").click(function(){
							databind.submitDom($("#constractCallback_dialog"), function(){
								base.alert(1, "打回成功！");
								dialog.hideDialog($("#constractCallback_dialog"));
							});
						});
					});
					
					//合同提交
					$(".submit-submitContract").unbind("click").click(function() {
						var $this = $(this);
						dialog.showConfirmDialog("合同提交", "是否确认提交合同？", function(){
							submitContract($this.parents("tr").attr("financeId"));
							router.route("main/main_finance.html?left=1&financeState=3&contractType=" + contractType, true);
						});
					});
					
					// 点击监管合同
					$(".submit-supervisionContract").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						submit_supervisionContract_event();
					});
					
					// 点击合同确认
					$(".submit-confirmContract").unbind("click").click(function() {
						var $this = $(this);
						pt = $(this).parents("tr").attr("productType");
						ii = layer.open({
						  type: 1,
						  title: "合同确认",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_contractConfirm,
						  btn: ['确定'],
						  yes: function(){
						  	if ($(".confirm").length > 0) {
						  		base.alert(2, "还有合同尚未确认！");
						  		return false;
						  	} else {
						  		layer.close(ii);
						  	}
						  },
						  cancel: function(){
						  	if ($(".confirm").length > 0) {
						  		base.alert(2, "还有合同尚未确认！");
						  		return false;
						  	} else {
						  		layer.close(ii);
						  	}
						  }
						});
						
						inquireFinanceContract2($this.parents("tr").attr("financeId"));
//						
//						$("#popdialog").html(html_constractCallBack);
//						$("#constractCallback_dialog .dialogTitle").html("合同确认");
//						$("select[name=callBackReason]").parent().remove();
//						$("#constractCallback_dialog").attr("action", "confirmContract");
//						$("#constractCallback_dialog input[name=contractType]").val(contractType);
//						$("#constractCallback_dialog input[name=financeId]").val($this.parents("tr").attr("financeId"));
//						$("#constractCallback_dialog textarea[name=callBackRemark]").attr({"placeholder": "请输入备注", "name": "remark"});
//						dialog.showDialog($("#constractCallback_dialog"));
//						
//						//确认按钮
//						$("#constractCallback_dialog .sure_yes").unbind("click").click(function(){
//							databind.submitDom($("#constractCallback_dialog"), function(){
//								dialog.hideDialog($("#constractCallback_dialog"));
//								base.alert(1, "确认成功！")
//								router.route("main/main_finance.html?left=1&financeState=3&contractType=" + contractType, true);
//							});
//						});
//						
//						//取消按钮
//						$("#constractCallback_dialog .sure_no").unbind("click").click(function(){
//							dialog.hideDialog($("#constractCallback_dialog"));
//						});
					});
					
					// 点击收货通知
					$(".button-submit-recieveNotice").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this);
						financeIds.push($this.parents("tr").attr("financeId"));
						financeNumbers.push($this.parents("tr").attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						initFinancingDetail(financeId);
						if ($(this).parents("tr").attr("productType") == 3 || $(this).parents("tr").attr("productType") == 5 || $(this).parents("tr").attr("productType") == 6) {
							var ii = layer.open({
							  title: '新增入库数据',
							  type: 1,
							  skin: 'layui-layer-rim', //加上边框
							  area: ['800px', '650px'], //宽高
							  content: html_financingDetail_recieveNotice_warehouse,
							  btn: ['确定', '取消'],
							  yes: function(){
							  	databind.submitDom($(".createWarehouseRecieveNotice"), function(){
							  		layer.msg("新增成功！");
							  		layer.close(ii);
							  		router.route("main/main_finance.html?left=2&financeState=5", true);
							  	});
							  }
							});
							
							$(".createWarehouseRecieveNotice .financeNumber").html(financeNumber);
							$(".createWarehouseRecieveNotice").append("<input type='hidden' name='financeId' value='"+financeId+"' />");
							
							var cacheData = tools.GetDataCache("inbound"+financeId);
							if (null != cacheData) {
								$(".createWarehouseRecieveNotice table").html(cacheData);
							}
							
							$(".createWarehouseRecieveNotice .addData").unbind("click").click(function(){
								var str = "<tr><td><input name='inboundNo' type='text'></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><a class='confirmData'>确认</a></td></tr>";
								$(".createWarehouseRecieveNotice .table").append(str);
							});
							
							$(".createWarehouseRecieveNotice").on("click", ".deleteData", function(){
								$(this).parents("tr").remove();
								
								tools.SetDataCache("inbound"+financeId, $(".createWarehouseRecieveNotice table").html());
							});
							
							$(".createWarehouseRecieveNotice").on("click", ".confirmData", function(){
								var $this = $(this);
								var str = "<tr><td class='data' name='result.inboundNo'></td><td class='data' name='result.warehouseName'></td><td class='data' name='result.goodsName'></td><td class='data' name='result.inboundQuantity'></td><td class='data' name='result.unit'></td><td class='data' name='result.specification'><a class='deleteData'>删除</a></td></tr>";
								databind.fillInput1($(str), {action:'searchInboundInfoForFinance.json?inboundNo=' + $this.parents("tr").find("input[name=inboundNo]").val()}, function(data) {
									var str = "<tr><td><input type='hidden' name='warehouseId' value='"+data.datas[0].result.warehouseId+"'/><input type='hidden' name='location_id' value='"+data.datas[0].result.location_id+"'/><input type='hidden' name='customerId' value='"+data.datas[0].result.customerId+"'/><input type='hidden' name='warehouseName' value='"+data.datas[0].result.warehouseName+"'/><input type='hidden' name='wareHouseNumbers' value='"+data.datas[0].result.inboundNo+"'/><input type='hidden' name='bulkstockInfoIds' value='"+data.datas[0].result.goodsId+"'/><input type='hidden' name='quantitys' value='"+data.datas[0].result.inboundQuantity+"'/><input type='hidden' name='weights' value='"+data.datas[0].result.inboundWeight+"'/><input type='hidden' name='volumes' value='"+data.datas[0].result.inboundVolume+"'/>"+data.datas[0].result.inboundNo+"</td><td>"+data.datas[0].result.warehouseName+"</td><td>"+data.datas[0].result.goodsName+"</td><td>"+data.datas[0].result.inboundQuantity+"</td><td>"+data.datas[0].result.inboundWeight+"</td><td>"+data.datas[0].result.unit+"</td><td>"+data.datas[0].result.specification+"</td><td>"+data.datas[0].result.location_area+"<input type='hidden' name='location_areas' value='"+data.datas[0].result.location_area+"'/></td><td>"+data.datas[0].result.location_name+"<input type='hidden' name='location_names' value='"+data.datas[0].result.location_name+"'/></td><td><a class='deleteData'>删除</a></td></tr>";
									$(".createWarehouseRecieveNotice .table").append(str);
									$this.parents("tr").remove();
								})
								
								tools.SetDataCache("inbound"+financeId, $(".createWarehouseRecieveNotice table").html());
							});
						} else {
							button_submit_recieveNotice_event();
							if ($(this).parents("tr").attr("productType") != '4') {
								base.alert(2, "请去融资申请详情填写提单！");
							}
						}
					});

					// 点击监管通知 button-submit-supervision
					$(".button-submit-supervision").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						initFinancingDetail(financeId);
						showSupervisionNotice(dataFinancingDetail);

					});
					// 进入审批
					$(".approveDetail").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
//						router.route("main/financeApprove.html?left=0&financeState=1&financeId="+ financeIds  + "&financeAuditId=" + $this.attr("financeAuditId"));
						$("#financeApprove").remove();
						$("#financeApprove6").remove();
						$("#financeApprove5_1").remove();
						if ($this.attr("productType") == "6") {
							router.route("main/financeApprove6.html?left=0&financeState=1&financeId=" + financeIds, true);
						} else if ($this.attr("productType") == "1" || $this.attr("productType") == "5") {
							router.route("main/financeApprove1_5.html?left=0&financeState=1&financeId=" + financeIds, true);
						} else {
							router.route("main/financeApprove.html?left=0&financeState=1&financeId=" + financeIds, true);
						}

						// 点击融资申请基本信息
						$(".financeDetailInfo").on("click",function() {
							router.route("main/financingDetailInfo.html?financeId=" + financeId);
						});
					});
					
					inquireCurrentOperationList();
					
					$(".editPro").unbind("click").click(function(){
						router.route("main/financeApprove.html?type=editPro&left=0&financeState=1&financeId="+ $(this).parents("tr").attr("financeId")  + "&financeAuditId=" + $(this).parents("tr").attr("financeAuditId"));
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
//		top.location.reload();
	};
	
	//合同确认
	var confirmContract =function(fid){
		base.fnAjax({
			action : "confirmContract.json",
			async : false, // 同步异步
			oData : {
				financeId: fid,
				contractType: 2
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	var inquireFinanceContract2 = function(fid) {
		base.fnAjax({
			action : "inquireFinanceContract.json",
			async : false, // 同步异步
			oData : {
				financeId : fid,
				contractType: 2
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm($(".contractConfirm"), data.datas[0]);
					if (pt == 5 || pt == 6) {
						if ($(".contractConfirm .submit-callBack").attr("class") == null) {
							$(".contractConfirm .confrimAll").after(' <a href="javascript:void(0);" class="submit-callBack">合同打回</a>');
						}
					}
					
					//合同打回
					$(".contractConfirm .submit-callBack").unbind("click").click(function() {
						$("#popdialog").html(html_constractCallBack);
						
						$("#constractCallback_dialog input[name=financeId]").val(fid);
						$("#constractCallback_dialog input[name=financeContractId]").val(data.datas[0].financeContractId);
						$("#constractCallback_dialog input[name=contractType]").val(2);
						
						tools.inquireCommonSelectorListByName("费用名称", $("#constractCallback_dialog select[name=callBackReason]"))
						
						dialog.showDialog($("#constractCallback_dialog"));
						
						//取消按钮点击事件
						$("#constractCallback_dialog .sure_no").unbind("click").click(function(){
							dialog.hideDialog($("#constractCallback_dialog"));
						});
						
						//确定按钮点击事件
						$("#constractCallback_dialog .sure_yes").unbind("click").click(function(){
							databind.submitDom($("#constractCallback_dialog"), function(){
								base.alert(1, "打回成功！");
								dialog.hideDialog($("#constractCallback_dialog"));
								layer.close(ii);
								personalWorkbench();
								inquireFinanceList();
							});
						});
					});
					
					$(".contractConfirm table").html("<tr><th></th><th>文件名称</th><th>文件类型</th><th>状态</th><th>退回原因</th><th>合同修改</th><th>签署记录</th><th>返回信息</th><th style='text-align:center;'>操作</th></tr>")
					var i = 1;
					$.each(data.datas[0].financeFilesInfoList, function() {
						var isSign = this.isSign;
						var filesInfoId = this.filesInfoId;
						var signState = this.fileSignState.split(',');
						var msg = [];
						if (this.msg != null) {
							msg = this.msg.split(',');
						}
						var j = 0;
						var fs1 = this.filesUuid.split(',');
						var ss1 = this.isSign.split(',');
						var fileType = this.normFileName;
						for (var x = 0; x < fs1.length; x++) {
							var _this = fs1[x];
							if ($.trim(_this) != "") {
								var m = msg[j];
								if (m == null || m == "null") {
									m = "";
								}
								var str;
								if (ss1[x] == '1') {
									if (signState[j] != 6 && signState[j] != 5) {
										if (signState[j] == 1) {
											str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a href='javascript:void(0);' class='confirm'>确认</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
										} else {
											str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
										}
									} else {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									}
								} else {
									if (signState[j] != 6 && signState[j] != 5) {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(80, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td></td><td></td><td style='text-align:right;'><a href='javascript:void(0);' class='confirm'>确认</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a> <a href='javascript:void(0);' class='callBack'>打回</a></td></tr>";
									} else {
										str = "<tr fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>"+fileType+"</td><td>"+constant.getValueByKey(80, signState[j])+"</td><td><a href='javascript:void(0);' class='callBackDetail'>详情</a></td><td><a href='javascript:void(0);' class='updateDetail'>详情</a></td><td></td><td></td><td style='text-align:right;'><a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
									}
								}
								if (str != null) {
									$(".contractConfirm table").append(str);
									i++;
									str = null;
								}
								m = "";
								j++;
							}
						};
						
					});
					
					//合同退回
					$(".contractConfirm .callBack").unbind("click").click(function(){
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".signCallback"), function(){
						  		layer.msg("退回成功！");
						  		layer.close(ii);
						  		inquireFinanceContract2(fid);
						  	});
						  }
						});
						
						$(".signCallback input[name=fileUuid]").val($(this).parents("tr").attr("fileUuid"));
						$(".signCallback input[name=financeId]").val(fid);
					});
					
					//合同确认
					$(".contractConfirm .confirm").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						//询问框
						ii4 = layer.confirm('是否确认该合同', {
						  btn: ['确定','取消'] //按钮
						}, function(){
						  confirmFinanceContract(fuid, fid);
						}, function(){
						  
						});
						
						$("input[name=fileUuid]").val(fuid);
					});
					
					//批量确认
					$(".contractConfirm .confrimAll").unbind("click").click(function(){
						//询问框
						var ii5 = layer.confirm('是否批量确认？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							if ($(".contractConfirm .confirm").length == 0) {
								confirmContract(fid);
							} else {
								$.each($(".contractConfirm .confirm"), function(){
									var fuid = $(this).parents("tr").attr("fileUuid");
									confirmFinanceContract1(fuid, fid);
									$("input[name=fileUuid]").val(fuid);
								});
								layer.close(ii5);
							}
							inquireFinanceContract2(fid);
							personalWorkbench();
							inquireFinanceList();
						}, function(){
						  
						});
						
					});
					
					//退回原因
					$(".contractConfirm .callBackDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "退回理由",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "callbackReamrk", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					//修改原因
					$(".contractConfirm .updateDetail").unbind("click").click(function(){
						var fuid = $(this).parents("tr").attr("fileUuid");
						
						var ii = layer.open({
						  type: 1,
						  title: "合同修改",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signCallback,
						  btn: ['确定']
						});
						
						$("textarea[name=remark]").attr({"name": "updateReamark", "readOnly": "readOnly"}).css("border", "none");
						
						databind.fillInput($(".signCallback"), {
							action: "inquireFinanceFilesInfoDetail.json?fileUuid="+fuid,
							version: "v1.0"
						});
					});
					
					//查看签署记录
					$(".contractConfirm .showSignRecord").unbind("click").click(function() {
						var $this = $(this);
						
						layer.open({
						  type: 1,
						  title: "签章记录",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['820px', '500px'], //宽高
						  content: html_signFileSealList,
						  btn: ['确定']
						});
						
						tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": $this.parents("tr").attr("fileUuid")}, function(){
							
						}, $(".signFileSealList .pagerCon"));
						
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	var inquireFinanceContract1 = function(financeId, isAll) {
		base.fnAjax({
			action : "inquireFinanceContract.json",
			async : false, // 同步异步
			oData : {
				financeId : financeId,
				contractType: 2
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm($(".html_documentSign"), data.datas[0]);
					
					$(".html_documentSign table").html("<tr><th><input type='checkbox' class='checkAll none'></th><th>No</th><th>文件名称</th><th>文件类型</th><th>状态</th><th>签署记录</th><th>退回原因</th><th>操作</th></tr>")
					var i = 1;
					$.each(data.datas[0].financeFilesInfoList, function() {
						var isSign = this.isSign;
						var filesInfoId = this.filesInfoId;
						var signState = this.fileSignState.split(',');
						var msg = [];
						if (this.msg != null) {
							msg = this.msg.split(',');
						}
						var j = 0;
						var fs1 = this.filesUuid.split(',');
						var ss1 = this.isSign.split(',');
//						$.each(this.filesUuid.split(','), function() {
						for (var x = 0; x < fs1.length; x++) {
							var _this = fs1[x];
							if ($.trim(_this) != "") {
								var m = msg[j];
								if (m == null || m == "null") {
									m = "";
								}
								var str;
								if (ss1[x] == '1') {
									str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input checked='checked' type='checkbox' class='checks none'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>签署文件</td><td>"+constant.getValueByKey(73, signState[j])+"</td><td><a href='javascript:void(0);' class='showSignRecord'>查看</td><td>"+m+"</td><td><a href='javascript:void(0);' class='sign'>签章</a> <a href='javascript:void(0);' class='changeSign'>取消网签</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
								} else {
									str = "<tr signState='"+signState[j]+"' fileUuid='"+_this+"' filesInfoId='"+filesInfoId+"' ><td><input type='checkbox' disabled='disabled' class='none'></td><td>"+i+"</td><td>"+tools.inquireFile(_this)+"</td><td>附件</td><td>-</td><td></td><td></td><td><a href='javascript:void(0);' class='changeSign'>设为网签</a> <a target='_blank' href='/finance/api/v1.0/viewPdfFile.json?fileUuid="+_this+"'>预览</a></td></tr>";
								}
								if (str != null) {
									$(".html_documentSign table").append(str);
									i++;
									str = null;
								}
								m = "";
								j++;
							}
						};
						
						tools.addCheckAllEvent($(".html_documentSign .checks"), $(".html_documentSign .checkAll"));
					});
					
					if(financeState == 23 || financeState == 22){
						$(".sign").remove();
					}
					
					//改变是否需要签署
					$(".html_documentSign .changeSign").unbind("click").click(function() {
						var $this = $(this);
						//询问框
						ii2 = layer.confirm('是否确认该操作？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							changeFileSign($this.parents("tr").attr("fileUuid"), financeId, isAll);
						}, function(){
						  
						});
					});
					
					//查看签署记录
					$(".html_documentSign .showSignRecord").unbind("click").click(function() {
						var $this = $(this);
						
						layer.open({
						  type: 1,
						  title: "签章记录",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['820px', '500px'], //宽高
						  content: html_signFileSealList,
						  btn: ['确定']
						});
						
						tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": $this.parents("tr").attr("fileUuid"), "isAll": isAll}, function(){
							if (isAll == true) {
								$(".cancelPos").remove();
							}
						}, $(".signFileSealList .pagerCon"));
						
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					});
					
					$(".html_documentSign .sign").unbind("click").click(function(){
						var $this = $(this);
						if (isAll == true) {
							window.open("../app/index.htm?fileUuid="+$this.parents("tr").attr("fileUuid")+"&readOnly=readOnly&enterpriseId="+ei);
						} else {
							window.open("../app/index.htm?fileUuid="+$this.parents("tr").attr("fileUuid"));
						}
					});
					
					$(".html_documentSign .signAll").unbind("click").click(function(){
						var filesInfoIds = [];
						var fileUuids = [];
						record = true;
						
						$.each($(".html_documentSign .checks:checked"), function() {
							var $this = $(this);
							if ($this.parents("tr").attr("signState") == "6") {
								filesInfoIds.push($this.parents("tr").attr("filesInfoId"));
								fileUuids.push($this.parents("tr").attr("fileUuid"));
							}
							
							inquireSignFileSealInfoPageList($this.parents("tr").attr("fileUuid"));
							if (record == false) {
								$this.parents("table").find("tr").css("background-color", "#FFF");
								$this.parents("tr").css("background-color", "pink");
								return false;
							}
						});
						
						if (record == false) {
							base.alert(2, "还有合同尚未签章！");
							return;
						}
						
						if (0 == filesInfoIds.length || 0 == fileUuids.length) {
							base.alert(2, "请勾选需要签署的文件！");
							return;
						}
						
						ii3 = layer.open({
						content: '是否确认签署？',
							btn: ['确认', '取消'],
							shadeClose: false,
							yes: function(){
							  	createPlatformDocumentSummarySignAll(financeId, filesInfoIds, fileUuids, 2);
							}, no: function(){
								layer.close(ii3);
							}
						});
					});
					
					if (isAll == true) {
						$(".signAll").remove();
						$(".sign").html("签章查看");
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	//合同确认
	var confirmFinanceContract =function(fileUuid, fid){
		base.fnAjax({
			action : "confirmFinanceContract.json",
			async : false, // 同步异步
			oData : {
				financeId: fid,
				fileUuid: fileUuid
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii4);
					inquireFinanceContract2(fid);
					personalWorkbench();
					inquireFinanceList();
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//合同确认1
	var confirmFinanceContract1 =function(fileUuid, fid){
		base.fnAjax({
			action : "confirmFinanceContract.json",
			async : false, // 同步异步
			oData : {
				financeId: fid,
				fileUuid: fileUuid
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//取消文件签章位置
	var cancelSealPos =function(signFileSealId, fileUuid){
		base.fnAjax({
			action : "cancelSealPos.json",
			async : false, // 同步异步
			oData : {
				signFileSealId: signFileSealId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii2);
					tools.loadList("inquireSignFileSealInfoPageList.json", $(".signFileSealList table"), $(".signFileSealList script"), {"fileUuid": fileUuid}, function(){
						$(".signFileSealList .cancelPos").unbind("click").click(function(){
							var $this1 = $(this);
							//询问框
							ii2 = layer.confirm('是否确认取消该签章', {
							  btn: ['确定','取消'] //按钮
							}, function(){
							  cancelSealPos($this1.parents("tr").attr("signFileSealId"), $this.parents("tr").attr("fileUuid"));
							}, function(){
							  
							});
						});
					}, $(".signFileSealList .pagerCon"));
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//取消文件签章位置
	var changeFileSign =function(fileUuid, financeId, isAll){
		base.fnAjax({
			action : "changeFileSign.json",
			async : false, // 同步异步
			oData : {
				fileUuid: fileUuid
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功");
					layer.close(ii2);
					inquireFinanceContract1(financeId, isAll);
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//批量签署
	var createPlatformDocumentSummarySignAll = function(financeId, filesInfoId, fileUuid, sealType){
		base.fnAjax({
			action : "createPlatformDocumentSummarySignAll.json",
			async : false, // 同步异步
			oData : {
				filesInfoId: filesInfoId,
				fileUuid: fileUuid,
				sealType: sealType,
				financeId: financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					layer.close(ii3);
					layer.close(ii);
					base.alert(1, "签署成功！");
					router.route("main/main_finance.html?left=4&financeState=3&contractType=2", true);
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	// 合同提交
	var submitContract = function(financeId) {
		base.fnAjax({
			action : 'submitContract.json',
			async : false,
			oData : {
				financeId : financeId,
				contractType: contractType
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					base.alert(1, "合同提交成功！");
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};

	// 权限控制
	var inquireCurrentOperationList = function() {
		base.fnAjax({
			action : 'inquireCurrentOperationList.json',
			async : false,
			fnSuccess : function(data) {
				if (data.status == 200) {
					for (var i = 0; i < data.datas.length; i++) {
						var permission = data.datas[i];
						var permissionId = permission.permissionId;
						$.each($("#main_finance").find(".permissionLink"),function() {
							var $this = $(this);
							if ($this.attr("permissionId") == permissionId) {
								$this.removeClass("none");
							}
						});
						$.each($("#financeContract_dialog").find(".permissionLink"),function() {
							var $this = $(this);
							if ($this.attr("permissionId") == permissionId) {
								$this.removeClass("none");
							}
						});
					}
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};

	// 查询融资信息列表
	var inquireFinanceList1 = function() {
		var productType = $("#main_finance select[name=productType]").val();
		var fb=$("#main_finance .financeNumber").val();
		base.fnAjax({
			action : "inquireFinanceList.json",
			async : false, // 同步异步
			nocode : false, // 是否要登陆，true为不用登陆
			oData : {
				pageIndex : pageIndex,
				pageSize : pageSize,
				financeNumber: fb,
				waybillNumber: $("#main_finance .waybillNumber").val(),
				enterpriseName: $("#main_finance .enterpriseName").val(),
				bulkstockName: $("#main_finance .bulkstockName").val(),
				productType : productType,
				caseNumber: $("#main_finance .caseNumber").val(),
				financeContractSerialNumber: $("#main_finance .financeContractSerialNumber").val()
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					var tpl = $("#financeListTpl").html();
					var html = juicer(tpl, data);
					$("#financeListBody").html(html);
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl(
						$("#main_finance .pagerCon"),
						totalRecordCount, data.pageIndex,
						data.pageSize, function(p) {
							pageIndex = p;
							inquireFinanceList1();
						});
					changeStatusColor();

					// 点击融资编号
					$(".order_num").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						router.route("financing/financingDetailInfo.html?financeId=" + financeId, true);
					});

					if (financeState == 1 || financeState == 23) {
						$(".locationContract").html("融资审批");
						$.each($("#financeListBody tr"), function() {
							var financeState1 = $(this).attr("financeState1");
							var $this = $(this);
							if (financeState1 !=9 && financeState1 !=18) {
								var detail = '<span class="approveDetail">进入审批</span>';
								$this.find(".detail").append(detail);
								$(".contractState").addClass("none");
							} else {
								var detail2 = '<span class="approveDetail">详情</span>';
								$this.find(".detail").append(detail2);
								$(".contractState").addClass("none");
//								$(".approveDetail1").unbind("click").click(function() {
//									router.route("main/financeApprove.html?financeId=" + $(this).parents("tr").attr("financeId")) + "&type=detail";
//								});
							}
						});
					} else if (financeState == 3) {
						$(".locationContract").html("合同上传");
						$.each($("#financeListBody tr"), function() {
							var financeState1 = $(this).attr("financeState1");
							var $this = $(this);
							if (financeState1 ==6 || financeState1 ==22 || financeState1 ==24) {
//								var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-submitContract ff2 permissionLink none" permissionId="financeContractSubmit_1">合同提交&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-confirmContract ff2 permissionLink none" permissionId="financeContractConfirm_1">合同确认&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-callBack ff2 permissionLink none" permissionId="financeCallBack_1">合同打回&nbsp;&nbsp;&nbsp;&nbsp;</div> </div>';
//								var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-confirmContract ff2">合同提交&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-confirmContract ff2 permissionLink none" permissionId="financeContractConfirm_1">合同确认&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="submit-callBack ff2 permissionLink none" permissionId="financeCallBack_1">合同打回&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
								var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div><div class="submit-confirmContract ff2">通过合同&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
								if (contractType == "3") {
									var detail = '我方签署&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div></div>';
								}
								$this.find(".detail").append(detail);
							} else {
								var detail = '融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow1_icon.png"/><div class="hideBtn"><div class="submit-financeContract1 ff1" style="left: 13px;">融资合同&nbsp;&nbsp;<img src="../../../res/png/arrow2_icon.png"/></div></div>';
								$this.find(".detail").append(detail);
							}
						});
					} else if (financeState == 5) {
//						$(".locationContract").html("通知锁定");
//						var detail = '通知锁定&nbsp;&nbsp;<div class="button-submit-recieveNotice ff2">通知锁定&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
//						$(".detail").append(detail);
						
						$(".locationContract").html("通知锁定");
						var detail = '通知锁定&nbsp;&nbsp;<div class="hideBtn"><div class="button-submit-recieveNotice ff2">通知锁定&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
						$(".detail").append(detail);
						tools.changeWarningColor($("#financeListBody"), "receiveCreateDatetime");
					}
					// 点击融资合同
					$(".submit-financeContract").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var delivers = [];
						var receives = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						delivers.push($this.attr("deliver"));
						receives.push($this.attr("receive"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						deliver = delivers;
						receive = receives;
						submit_financeContract_event();
					});

					// 点击融资合同详情
					$(".submit-financeContract1").unbind("click").click(function() {
						var $this = $(this);
						var financeContractId1 = $(this).parents("tr").attr("financeContractId");
						$("#popdialog").html(html_financingDetail_financeContract);
						var financeContract_dialog = $("#financeContract_dialog");
						dialog.showDialog(financeContract_dialog, function() {
							dialog.hideDialog(financeContract_dialog);
						});
						databind.fillInput1($("#financeContract_dialog"),{action : "inquireFinanceContract.json?financeId=" + $this.parents("tr").attr("financeId") + "&contractType=" + contractType, version : "v1.0", async : false }, function(data){
							var tpl = '{@each datas as it, index}' +
									'{@each it.financeFilesInfoList as item, index}' +
									'<div style="margin-top: 15px;">' +
									'<input type="hidden" name="filesInfoId" value="${item.filesInfoId}" />' +
									'<input type="hidden" name="filesSign" value="${item.isSign}" />' +
									'<input isNull="${item.isNotNull}" codeName="${item.normFileName}" type="hidden" value="${item.filesUuid}" name="filesUuid" />' +
									'<input multiple="multiple" type="file" id="normFileName${index}" name="file" class="none normFileName" />' +
									'<span class="none${item.isNotNull}" style="color: red;">*</span><span>${item.normFileName}：</span><label for="normFileName${index}" class="productIntro">添加</label>' +
									'</div>' +
									'{@/each}' +
									'{@/each}';
							var html = juicer(tpl, data);
							$("#financeContract_dialog .normInfos").append(html);
							
							$.each($("#financeContract_dialog input[name=filesUuid]"), function(){
								var $this1 = $(this);
								$.each($this1.val().split(','), function() {
									var f = this;
									if (f != "") {
										var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + f + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" class="showProductIntro">' + tools.inquireFile(f) + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
										$this1.parent().find(".productIntro").before(str);
									}
								});
							});
						});
						var str = $("#materials").val().split(",");
						$.each(str, function(i, s) {
							$(".uploadImgP").parent().append(
								'<a fhref="'+s+'" style="display:inline-block;" target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid='
								+ s
								+ '"><img style="width: 100px; height: 100px; display: inline-block;" src="../../../res/png/file_icon.png" /><br/><span class="contactFileName">'
								+ tools.inquireFile(s)
								+ '</span></a>'
							);
						});
						databind.disableInput($("#financeContract_dialog"));
						$("#financeContract_dialog .crossScreen").removeAttr("readonly");
						$("#financeContract_dialog .crossScreen").removeAttr("disabled");
						$("#sure_yes").remove();
						$(".uploadImgP").css("display", "none");
						
//						$("#financeContract_dialog").on("click", "a", function(){
//							var $this = $(this);
//							if ($("#financeContract_dialog .crossScreen").prop("checked") == true) {
//								$this.attr({"target": "", "href": "javascript:void(0);"});
//								if (rd == null) {
//									getRandomCode(function(){
//										passData(rd, $this.attr("fhref"));
//										window.open("../crossingScreen/pc/index2.html?randomCode=" + rd);
//									});
//								} else {
//									passData(rd, $this.attr("fhref"));
//								}
//							} else {
//								$this.attr({"target": "_blank", "href": "/finance/api/v1.0/downloadFile.file?fileUuid=" + $this.attr("fhref")});
//							}
//						});
					});

					// 点击监管合同
					$(".submit-supervisionContract").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						submit_supervisionContract_event();
					});

					// 点击监管合同详情
					$(".submit-supervisionContract1").unbind("click").click(function() {
						var supervisionContractId1 = $(this).parents("tr").attr("supervisionContractId");
						$("#popdialog").html(html_financingDetail_supervisionContract);
						var supervisionContract_dialog = $("#supervisionContract_dialog");
						dialog.showDialog(supervisionContract_dialog, function() {});
						loadLogisticsCompanyPageList("supervisionCompanyName", "supervisionTpl");
						base.fnAjax({
							action : "inquireSupervisionContractDetail.json",
							async : false,
							oData : {
								supervisionContractId : supervisionContractId1
							}, // 传递参数
							fnSuccess : function(data) {
								if (data.status == 200) {
									databind.fillForm(".supervisionContractContent_submit", data.datas[0]);
									var str = $("#materials").val().split(",");
									$.each(str, function(i, s) {
										$(".uploadImgP").parent().append(
										'<a style="display:inline-block;" target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid='
										+ s
										+ '"><img style="width: 100px; height: 100px; display: inline-block;" src="../../../res/png/file_icon.png" /><br /><span class="contactFileName">'
										+ tools.inquireFile(s)
										+ '</span></a>');
									});
									databind.disableInput($("#supervisionContract_dialog"));
									$("#sure_yes").remove();
									$(".uploadImgP").css("display", "none");
								} else {
									base.alert(2,"信息获取失败");
								}
							}
						});
					});

					// 点击通过合同
					$(".submit-confirmContract").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						dialog.showConfirmDialog("合同审核", "确定要通过此合同审核吗？", function() {
							confirmContract();
						});
					});
					
					// 点击收货通知
					$(".button-submit-recieveNotice").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this);
						financeIds.push($this.parents("tr").attr("financeId"));
						financeNumbers.push($this.parents("tr").attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						initFinancingDetail(financeId);
						if ($(this).parents("tr").attr("productType") == 3 || $(this).parents("tr").attr("productType") == 5 || $(this).parents("tr").attr("productType") == 6) {
							var ii = layer.open({
							  title: '新增入库数据',
							  type: 1,
							  skin: 'layui-layer-rim', //加上边框
							  area: ['800px', '650px'], //宽高
							  content: html_financingDetail_recieveNotice_warehouse,
							  btn: ['确定', '取消'],
							  yes: function(){
							  	databind.submitDom($(".createWarehouseRecieveNotice"), function(){
							  		layer.msg("新增成功！");
							  		layer.close(ii);
							  		router.route("main/main_finance.html?left=2&financeState=5", true);
							  	});
							  }
							});
							
							$(".createWarehouseRecieveNotice .financeNumber").html(financeNumber);
							$(".createWarehouseRecieveNotice").append("<input type='hidden' name='financeId' value='"+financeId+"' />");
							
							var cacheData = tools.GetDataCache("inbound"+financeId);
							if (null != cacheData) {
								$(".createWarehouseRecieveNotice table").html(cacheData);
							}
							
							$(".createWarehouseRecieveNotice .addData").unbind("click").click(function(){
								var str = "<tr><td><input name='inboundNo' type='text'></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><a class='confirmData'>确认</a></td></tr>";
								$(".createWarehouseRecieveNotice .table").append(str);
							});
							
							$(".createWarehouseRecieveNotice").on("click", ".deleteData", function(){
								$(this).parents("tr").remove();
								
								tools.SetDataCache("inbound"+financeId, $(".createWarehouseRecieveNotice table").html());
							});
							
							$(".createWarehouseRecieveNotice").on("click", ".confirmData", function(){
								var $this = $(this);
								var str = "<tr><td class='data' name='result.inboundNo'></td><td class='data' name='result.warehouseName'></td><td class='data' name='result.goodsName'></td><td class='data' name='result.inboundQuantity'></td><td class='data' name='result.unit'></td><td class='data' name='result.specification'><a class='deleteData'>删除</a></td></tr>";
								databind.fillInput1($(str), {action:'searchInboundInfoForFinance.json?inboundNo=' + $this.parents("tr").find("input[name=inboundNo]").val()}, function(data) {
									var str = "<tr><td><input type='hidden' name='location_id' value='"+data.datas[0].result.location_id+"'/><input type='hidden' name='customerId' value='"+data.datas[0].result.customerId+"'/><input type='hidden' name='warehouseName' value='"+data.datas[0].result.warehouseName+"'/><input type='hidden' name='wareHouseNumbers' value='"+data.datas[0].result.inboundNo+"'/><input type='hidden' name='bulkstockInfoIds' value='"+data.datas[0].result.goodsId+"'/><input type='hidden' name='quantitys' value='"+data.datas[0].result.inboundQuantity+"'/><input type='hidden' name='weights' value='"+data.datas[0].result.inboundWeight+"'/><input type='hidden' name='volumes' value='"+data.datas[0].result.inboundVolume+"'/>"+data.datas[0].result.inboundNo+"</td><td>"+data.datas[0].result.warehouseName+"</td><td>"+data.datas[0].result.goodsName+"</td><td>"+data.datas[0].result.inboundQuantity+"</td><td>"+data.datas[0].result.inboundWeight+"</td><td>"+data.datas[0].result.unit+"</td><td>"+data.datas[0].result.specification+"</td><td>"+data.datas[0].result.location_area+"<input type='hidden' name='location_areas' value='"+data.datas[0].result.location_area+"'/></td><td>"+data.datas[0].result.location_name+"<input type='hidden' name='location_names' value='"+data.datas[0].result.location_name+"'/></td><td><a class='deleteData'>删除</a></td></tr>";
									$(".createWarehouseRecieveNotice .table").append(str);
									$this.parents("tr").remove();
								})
								
								tools.SetDataCache("inbound"+financeId, $(".createWarehouseRecieveNotice table").html());
							});
						} else {
							button_submit_recieveNotice_event();
							if ($(this).parents("tr").attr("productType") != '4') {
								base.alert(2, "请去融资申请详情填写提单！");
							}
						}
					});

					// 点击监管通知 button-submit-supervision
					$(".button-submit-supervision").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						financeNumbers.push($this.attr("financeNumber"));
						financeId = financeIds;
						financeNumber = financeNumbers;
						initFinancingDetail(financeId);
						showSupervisionNotice(dataFinancingDetail);
					});
					
					// 进入审批
					$(".approveDetail").unbind("click").click(function() {
						var financeIds = [];
						var financeNumbers = [];
						var $this = $(this).parents("tr.tr_style");
						financeIds.push($this.attr("financeId"));
						$("#financeApprove").remove();
						$("#financeApprove6").remove();
						$("#financeApprove5_1").remove();
						if ($this.attr("productType") == "6") {
							router.route("main/financeApprove6.html?left=0&financeState=1&financeId=" + financeIds, true);
						} else if ($this.attr("productType") == "1" || $this.attr("productType") == "5") {
							router.route("main/financeApprove1_5.html?left=0&financeState=1&financeId=" + financeIds, true);
						} else {
							router.route("main/financeApprove.html?left=0&financeState=1&financeId=" + financeIds, true);
						}
						// 点击融资申请基本信息
						$(".financeDetailInfo").on("click", function() {
							router.route("main/financingDetailInfo.html?financeId=" + financeId, true);
						});
					});
					
					$(".editPro").unbind("click").click(function(){
						router.route("main/financeApprove.html?type=editPro&left=0&financeState=1&financeId="+ $(this).parents("tr").attr("financeId")  + "&financeAuditId=" + $(this).parents("tr").attr("financeAuditId"));
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
//		top.location.reload();
	};
	
	var passData = function(randomCode, data) {
		base.fnAjax({
			action: "passData.json",
			oData: {
				randomCode: randomCode,
				data: data
			},
			fnSuccess: function(data) {
				if (data.status == 200) {
					
				} else {
					base.alert(3, data.message);
				}
			}
		});
	}

	var initFinancingDetail = function(financeId) {
		base.fnAjax({
			action : "inquireFinanceApplicationDetail.json",
			async : false,
			oData : {
				financeId : financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					dataFinancingDetail = data;
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}

	// 显示监管通知信息页面
	var showSupervisionNotice = function(dataFinancingDetail) {
		$("#popdialog").html(html_financingDetail_supervisionInform);
		var supervisionInform_dialog = $("#supervisionInform_dialog");
		dialog.showDialog(supervisionInform_dialog, function() {
		});
		var tpl = $("#supervisionInform").html();
		var html = juicer(tpl, dataFinancingDetail);
		$(".supervisionInformContent").html(html);
		inquireSupervisionContractToSupervisionNotice();
		inquireFinanceSupervisionNotice(dataFinancingDetail);

	}
	// 监管通知获取监管合同和监管物流
	var inquireSupervisionContractToSupervisionNotice = function() {
		base.fnAjax({
			action : "inquireFinanceSupervisionContract.json",
			oData : {
				financeId : financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					data.datas[0].financeId = financeId;
					databind.fillForm(".dialogContent-recieveNotice",
							data.datas[0]);
					databind.fillForm(".supervisionInformContent",
							data.datas[0]);
					
					$("#recieveNotice_dialog .data[name=financeNumber]").html(financeNumber);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	//获取随机码
	var getRandomCode = function(callback) {
		base.fnAjax({
			action: "getRandomCode.json",
			oData: {
			},
			fnSuccess: function(data) {
				if (data.status == 200) {
					rd = data.datas[0].randomCode;
					callback();
				} else {
					base.alert(3, data.message);
				}
			}
		});
	}
	
	// 查看融资监管通知信息
	var inquireFinanceSupervisionNotice = function(dataFinancingDetail) {
		base.fnAjax({
			action : "inquireFinanceSupervisionNotice.json",
			oData : {
				financeId : financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					databind.fillForm(".supervisionInformContent",
							dataFinancingDetail.datas[0]);
					if (data.datas.length > 0
							&& data.datas[0].supervisionNoticeId != 0) {
						databind.fillForm(".supervisionInformContent",
								data.datas[0]);

						$(".supervisionInformContent").attr("action",
								"updateSupervisionNotice");
					}

				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
		// 监管通知点击确认
		$("#sure_yes").on("click", function() {
			var supervisionNoticeId = $("#supervisionNoticeId").val();

			if (supervisionNoticeId.length == 0 || supervisionNoticeId == 0) {
				createSupervisionNotice();
			} else {
				updateSupervisionNotice();
			}

		});

	}
	// 创建监管通知
	var createSupervisionNotice = function() {
		databind.submitDom(".supervisionInformContent", function(data) {
			databind.fillForm(".supervisionInformContent", {
				supervisionNoticeId : data.datas[0].supervisionNoticeId
			});
			$(".supervisionInformContent").attr("action", "updateSupervisionNotice");
			base.alert(2, "创建监管通知成功，请去融资申请详情填写提单！");
			dialog.hideDialog($("#supervisionInform_dialog"));
			router.route("main/main_finance.html?left=2&financeState=5", true);
		});
	}

	var updateSupervisionNotice = function() {
		databind.submitDom(".supervisionInformContent", function() {
			base.alert(1, "修改监管通知成功");
			dialog.hideDialog($("#supervisionInform_dialog"));
			router.route("main/main_finance.html?left=2&financeState=5", true);
		});
	}

	// 判断是创建还是修改融资合同
	var inquireFinanceContract = function() {
		base.fnAjax({
			action : "inquireFinanceContract.json",
			async : false, // 同步异步
			oData : {
				financeId : financeId,
				contractType: contractType
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					if (data.datas[0].isSign == 1) {
						$("input[name=isSign]").prop("checked", true);
					} else {
						$("input[name=isSign]").prop("checked", false);
					}
					
					if (data.datas.length > 0 && data.datas[0].financeContractId != 0) {
						$("#financeContract_dialog .uploadImgP label").remove();
						
						databind.fillForm(".financeContract", data.datas[0]);
						$(".financeContract").attr("action", "updateFinanceContract");
						showImg(data.datas[0].materials);
						var tpl = '{@each datas as it, index}' +
								'{@each it.financeFilesInfoList as item, index}' +
								'<div style="margin-top: 15px;">' +
								'<input type="hidden" name="filesInfoId" value="${item.filesInfoId}" />' +
								'<input isNull="${item.isNotNull}" codeName="${item.normFileName}" type="hidden" value="${item.filesUuid}" name="filesUuid" />' +
								'<input type="hidden" name="filesSign" value="${item.isSign}" />' +
								'<input type="hidden" name="fileSignState" value="${item.fileSignState}" />' +
								'<input multiple="multiple" type="file" id="normFileName${index}" name="file" class="none normFileName" />' +
								'<span class="none${item.isNotNull}" style="color: red;">*</span><span>${item.normFileName}：</span><label for="normFileName${index}" class="productIntro">添加</label>' +
								'<table style="border: none;">' +
								'	<tr>' +
								'		<th width="5%" style="padding-left: 0;">No</th>' +
								'		<th width="55%" >文件名称</th>' +
								'		<th width="10%" >附件类型</th>' +
								'		<th width="10%" class="signTitle">签署</th>' +
								'		<th width="20%" >操作</th>' +
								'	</tr>' +
								'</table>' +
								'</div>' +
								'{@/each}' +
								'{@/each}';
						var html = juicer(tpl, data);
						$("#financeContract_dialog .normInfos").html(html);
						
						$.each($("#financeContract_dialog input[name=filesUuid]"), function(){
							var $this1 = $(this);
							var fs1 = $this1.val().split(',');
							var ss1 = $this1.parent().find("input[name=filesSign]").val().split(',');
							var signState = $this1.parent().find("input[name=fileSignState]").val().split(',');
							for(var x = 0; x < fs1.length; x++){
								var f = fs1[x];
								if (f != "") {
									if (ss1[x] == "1") {
										if (signState[x] == 5) {
											var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input checked="checked" type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="replace">替换</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
											$this1.parent().find("table").append(str);
										} else {
											var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input checked="checked" type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
											$this1.parent().find("table").append(str);
										}
									} else {
										if (signState[x] == 5) {
											var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="replace">替换</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
											$this1.parent().find("table").append(str);
										} else {
											var str = '<tr fileUuid="'+f+'" class="mas"><td class="fileIndex">'+parseInt(x+1)+'</td><td><a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + f + '" target="_blank">'+tools.inquireFile(f)+'</a></td><td>'+$this1.attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
											$this1.parent().find("table").append(str);
										}
									}
								}
							};
						});
					} else {
						databind.fillForm(".financeContract", {
							financeNumber : financeNumber,
							financeId : financeId,
							receive : receive,
							deliver : deliver
						});
						$("#financeContract_dialog .uploadImgP").remove();
						inquireFinanceFilesNormList();
					};
					
					for (var i = 0; i < $("#financeContract_dialog .normFileName").length; i++) {
						var $this = $("#" + $($("#financeContract_dialog .normFileName")[i]).attr("id"));
						tools.fileupload($this, null, function (data, dom) {
							var d = $("#" + $(dom).attr("id"));
//							var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showProductIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
							var str = "";
							if (financeState == 31) {
								$(".signTitle").hide();
								str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input style="display:none" type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
							} else {
								str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
							}
							//							d.parent().find(".productIntro").before(str);
							d.parent().find("table").append(str);
							var fileUuid = [];
							var fileSign = [];
							for (var j = 0; j < d.parent().find(".mas").length; j++) {
								fileUuid.push($(d.parent().find(".mas")[j]).attr("fileUuid"));
								$(d.parent().find(".mas")[j]).find(".fileIndex").html(j+1);
								if ($(d.parent().find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.parent().find("input[name=filesUuid]").val(fileUuid);
							d.parent().find("input[name=filesSign]").val(fileSign);
							
							if (pt == "2") {
								$("#financeContract_dialog input[type=checkbox]").prop("checked", false).attr("disabled", "disabled").hide();
								$("#financeContract_dialog input[name=isSign]").parent().hide();
								$("#financeContract_dialog .crossScreen").removeAttr("disabled").show();
							}
						});
					};
					
					$("#financeContract_dialog").on("click", ".deleteProductIntro", function() {
						var d = $(this).parent().parent().parent().parent().parent();
						$(this).parents("tr").remove();
						var fileUuid = [];
						var fileSign = [];
						for (var j = 0; j < d.find(".mas").length; j++) {
							fileUuid.push($(d.find(".mas")[j]).attr("fileUuid"));
							$(d.find(".mas")[j]).find(".fileIndex").html(j+1);
							if ($(d.find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
								fileSign.push(1);
							} else {
								fileSign.push(0);
							}
						}
						d.find("input[name=filesUuid]").val(fileUuid);
						d.find("input[name=filesSign]").val(fileSign);
					});
					
					$("#financeContract_dialog").on("click", "table input[type=checkbox]", function() {
						var d = $(this).parent().parent().parent().parent().parent();
						var fileSign = [];
						for (var j = 0; j < d.find("input[type=checkbox]").length; j++) {
							if ($(d.find("input[type=checkbox]")[j]).prop("checked")) {
								fileSign.push(1);
							} else {
								fileSign.push(0);
							}
						}
						d.find("input[name=filesSign]").val(fileSign);
					});
					
					$("#financeContract_dialog .replace").unbind("click").click(function(){
						var ii = layer.open({
						  type: 1,
						  title: "合同修改",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['620px', '300px'], //宽高
						  content: html_signReplace,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".signReplace"), function(){
						  		layer.msg("修改成功！");
						  		layer.close(ii);
						  		inquireFinanceContract();
						  	});
						  }
						});
						
						$(".signReplace input[name=financeId]").val(financeId);
						$(".signReplace input[name=oldFileUuid]").val($(this).parents("tr").attr("fileUuid"));
						tools.fileupload($("#newFile"), null, function (data, dom) {
							var str = '<a target="_blank" href="/finance/api/v1.0/downloadFile.file?fileUuid='+data.result.data[0].fileUuid+'">'+data.result.data[0].fileName+'</a>';
							$("#newFile").parent().find("span").html(str);
							$(".signReplace input[name=newFileUuid]").val(data.result.data[0].fileUuid);
						});
					});
					
					if (pt == "2") {
						$("#financeContract_dialog input[type=checkbox]").prop("checked", false).attr("disabled", "disabled").hide();
						$("#financeContract_dialog input[name=isSign]").parent().hide();
						$("#financeContract_dialog .crossScreen").removeAttr("disabled").show();
					}
					
//					if (constractState != "0" && constractState != "1" && constractState != "2") {
//						$("#financeContract_dialog .productIntro").remove();
//						$("#financeContract_dialog .deleteProductIntro").remove();
//					}
					
					if (financeConstractState == "9") {
						$("#financeContract_dialog .productIntro").remove();
						$("#financeContract_dialog .deleteProductIntro").remove();
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	
	//查询文件印章信息
	var inquireSignFileSealInfoPageList =function(fileUuid){
		base.fnAjax({
			action : "inquireSignFileSealInfoPageList.json",
			async : false, // 同步异步
			oData : {
				fileUuid: fileUuid,
				signState: 0
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					if (data.datas.length == 0) {
						record = false;
					}
				} else {
					base.alert(2, data.message);
				}
			}
		});
	}

	// 修改融资合同
	var updateFinanceContract = function() {
		
		databind.submitDom("#financeContract_dialog .financeContract", function(data) {
			base.alert(1, "上传" + contractTypeName + "成功！");
			dialog.hideDialog($("#financeContract_dialog"));
			router.route("main/main_finance.html?left=1&financeState=3&contractType=" + contractType, true);
		});
	}

	// 创建融资合同
	var createFinanceContract = function() {
		databind.submitDom("#financeContract_dialog .financeContract", function(data) {
			databind.fillForm("#financeContract_dialog .financeContract", {
				financeContractId : data.datas[0].financeContractId
			});
			databind.fillInput("#financeContract_dialog .financeContract", {
				action : "inquireFinanceContractDetail.json",
				version : "v1.0"
			});

			$("#financeContract_dialog .financeContract").attr("action", "updateFinanceContract");
			base.alert(1, "上传" + contractTypeName + "成功！");
			dialog.hideDialog($("#financeContract_dialog"));
			if (financeState == 31) {
				router.route("main/main_finance.html?left=9&financeState=31&contractType=" + contractType, true);
			} else {
				router.route("main/main_finance.html?left=1&financeState=3&contractType=" + contractType, true);
			}
		});
	}
	// 修改监管合同
	var updateSupervisionContract = function() {
		databind.submitDom(".supervisionContractContent_submit", function(data) {
			base.alert(1, "上传监管合同成功！");
			dialog.hideDialog($("#supervisionContract_dialog"));
			router.route("main/main_finance.html?left=1&financeState=3", true);
		});
	}

	// 创建监管合同
	var createSupervisionContract = function() {
		databind.submitDom(".supervisionContractContent_submit", function(data) {
			databind.fillForm(".supervisionContractContent_submit", {supervisionContractId : data.datas[0].supervisionContractId});
			databind.fillInput(".supervisionContractContent_submit",{
				action : "inquireSupervisionContractDetail.json",
				version : "v1.0"
			});
	
			$(".financeContractContent_submit").attr("action", "updateSupervisionContract");
			base.alert(1, "上传监管合同成功！");
			dialog.hideDialog($("#supervisionContract_dialog"));
			router.route("main/main_finance.html?left=1&financeState=3", true);
		});
	}
	
	// 判断是创建还是修改监管合同
	var inquireFinanceSupervisionContract = function() {
		base.fnAjax({
			action : "inquireFinanceSupervisionContract.json",
			oData : {
				financeId : financeId
			}, // 传递参数
			fnSuccess : function(data) {
				if (data.status == 200) {
					if (data.datas.length > 0 && data.datas[0].supervisionContractId != 0) {
						databind.fillForm(".supervisionContractContent_submit", data.datas[0]);
						$(".supervisionContractContent_submit").attr("action", "updateSupervisionContract");
						showImg(data.datas[0].materials);
					} else {
						databind.fillForm(".supervisionContractContent_submit",{
							financeNumber : financeNumber,
							financeId : financeId
						});
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	var loadLogisticsCompanyPageList = function(bodyDomId, jsTpl) {
		base.fnAjax({
			action : "inquireLogisticsCompanyListByCompanyName.json",
			version : "v1.0",
			async : false,
			oData : {
				pageIndex : 1,
				pageSize : 1000
			}, // 传递参数
			fnSuccess : function(data) { // 成功回调
				if (data.status == 200) {
					var tpl = $("#" + jsTpl).html();
					var html = juicer(tpl, data);
					$("#" + bodyDomId).html(html);
					
				} else {
					base.alert(3, data.message);
				}
			}
		});

		// 下发运输通知 绑定点击物流方事件
		$("#transportCompanyName").change(function() {
			var companyName = $("#transportCompanyName option:selected").text();
			$(".supervisionCompanyNameInput").val(companyName);
		});

		// 绑定点击物流方事件
		$("#supervisionCompanyName").change(function() {
			var companyName = $("#supervisionCompanyName option:selected").text();
			$(".supervisionCompanyNameInput").val(companyName);
		});
	}

	var uploadFile = function() {
		
		if ($("#uploadFile1024").val() != "") {
//			var fileType = "doc,pdf,jpg,png,bmp,docx";
//			var prompt = validate.validateFileType($("#uploadFile1024"), fileType);
//			if (prompt.length > 1) {
//				base.alert(2, prompt);
//				return;
//			}
			$.ajaxFileUpload({
				url : "/finance/api/v1.0/uploadFile.json", // 你处理上传文件的服务端
				secureuri : false,
				fileElementId : "uploadFile1024",
				dataType : 'json',
				success : function(data) {
					var imgSrc = "";
					var html = "";
					imgSrc = data.data[0].fileUuid;
					var fileNameStr = data.data[0].fileName;
					var fileNameStrs = fileNameStr.split(".");
					if (fileNameStrs[0].length > 10) {
						fileNameStr = fileNameStrs[0].substr(0, 10);
					}
					var fileName = fileNameStr.split(".");
					html = '<a target="_blank" href="/finance/api/1.0/downloadFile.file?fileUuid=' + imgSrc + '" fhref="' + imgSrc + '">';
					html += '<div class="finance-file" id="' + imgSrc + '">';
					html += '<img  src="../../../res/png/file_icon.png" class="finance-field-img"  alt="' + imgSrc + '" data-name="' + fileNameStr + '" />';
					html += '<a class="closeLayer" ></a><div class="fileName">' + fileNameStr + '</div></div></a>';
					$(".uploadImgP label").before(html);
					saveMaterials();
				},
				complete : function(xml) {
					$("#uploadFile1024").on('change', function() {
						uploadFile();
					});
				},
				error : function(data, status, e) {
					base.alert(2, "参数错误");
				}
			});
		} else {
			base.alert(3, "请选择文件！");
		}
	}

	// 更新fileUuuid保存字段
	var saveMaterials = function() {
		var materials = "";
		var imageNames="";
		var number = $(".finance-field-img").length;
		$(".finance-field-img").each(function(i, object) {
			if (i == number - 1) {
				var url=$(object).attr("data-name");
				imageNames +=url; // url.substring(0,url.length);
				materials += object.alt;
			} else {
				var url=$(object).attr("data-name");
				imageNames +=url+","; // url.substring(0,url.length)+",";
				materials += object.alt + ",";
			}

		});
		$("#imageNames").val(imageNames);
		$("#materials").val(materials);
	}
	
	// 显示图片
	var showImg = function(materials) {
		var fileUuids = materials.split(",");
		var html = "";
		var imgSrc = "";
		for (var i = 0; i < fileUuids.length; i++) {
			imgSrc = fileUuids[i];
			if (imgSrc.length != 0) {
				html = '<a target="_Blank" href="/finance/api/1.0/downloadFile.file?fileUuid=' + imgSrc + '" fhref="' + imgSrc + '">';
				html += '<div class="finance-file" id="' + imgSrc + '">';
				html += '<img  src="../../../res/png/file_icon.png" class="finance-field-img"  alt="' + imgSrc + '" />';
				html += '<a class="closeLayer permissionLink none" permissionId="financeContractManage_1"></a><div class="fileName"></div>'+ tools.inquireFile(imgSrc) +'</div></a>';
				$(".uploadImgP").append(html);
			}
		}
	}
	
	// 改变融资状态背景色
	var changeStatusColor = function() {
		var status = $(".order_status");
		for (var i = 0, j = status.length; i < j; i++) {
			switch ($.trim(status[i].innerHTML)) {
			case "融资":
				$(status[i]).css("background-color", "#6BA8E7");
				break;
			case "换货":
				$(status[i]).css("background-color", "#28BF85");
				break;
			}
		}
	};

	return {
		init : init
	};
});